package com.atguigu.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.concurrent.TimeUnit;

@Service
public class PaymentService {
    public String paymentInfo_ok(Integer id){
        return "线程池： "+Thread.currentThread().getName()+" PaymentInfo_Ok,id: "+id+"\t"+"O(∩_∩)O哈哈~";
    }
    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public String paymentInfo_TimeOut(Integer id){
        try{
            TimeUnit.SECONDS.sleep(2);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        finally {

        }
        return "线程池： "+Thread.currentThread().getName()+" PaymentInfo_TimeOut,id: "+id+"\t"+"O(∩_∩)O哈哈~"+"耗时3秒钟";
    }
    public String paymentInfo_TimeOutHandler(Integer id){
        return "线程池： "+Thread.currentThread().getName()+" PaymentInfo_TimeOutHandler,id: "+id+"\t"+"系统繁忙或运行报错o(╥﹏╥)o呜呜~"+"耗时3秒钟";
    }
}
